# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgname=pacrunner
pkgver=0.19
pkgrel=2
pkgdesc="Proxy configuration daemon"
arch=(loong64 x86_64)
url="https://git.kernel.org/pub/scm/network/connman/pacrunner.git"
license=(GPL2 LGPL2.1)
depends=(glib2 dbus curl duktape)
makedepends=(git)
options=(debug)
_commit=bb888a1f99cc05d63bd61b65cad7026feea92a4e  # tags/0.19^0
source=("git+https://git.kernel.org/pub/scm/network/connman/pacrunner.git#commit=$_commit"
        duktape-shared.diff)
sha256sums=('SKIP'
            '2cbb148bc7cd72230a1aa465c806260eb0fc1dd47d8663b2b48d25cc29622d02')

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/-/+/g'
}

prepare() {
  cd $pkgname

  # Use our system duktape
  git apply -3 ../duktape-shared.diff

  ./bootstrap
}

build() {
  cd $pkgname
  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --sbindir=/usr/bin \
    --libexecdir=/usr/lib \
    --with-dbusconfdir=/usr/share \
    --enable-pie \
    --enable-duktape \
    --enable-curl
  make
}

package() {
  cd $pkgname
  make DESTDIR="$pkgdir" install

  install -Dm644 /dev/stdin "$pkgdir/usr/lib/systemd/system/pacrunner.service" <<END
[Unit]
Description=Proxy configuration daemon
Before=network.target
Wants=network.target

[Service]
Type=dbus
BusName=org.pacrunner
ExecStart=/usr/bin/pacrunner

[Install]
WantedBy=multi-user.target
END

  install -Dm644 /dev/stdin "$pkgdir/usr/share/dbus-1/system-services/org.pacrunner.service" <<END
[D-BUS Service]
Name=org.pacrunner
Exec=/usr/bin/pacrunner
User=root
SystemdService=pacrunner.service
END
}

# vim:set sw=2 sts=-1 et:
